package com.easyfun.healthmagicbox;

import com.easyfun.healthmagicbox.auth.LoginActivity;
import com.easyfun.healthmagicbox.base.BaseActivity;
import com.easyfun.healthmagicbox.comm.ForgetPasswordTask;
import com.easyfun.healthmagicbox.inputviews.DietInputActivity;
import com.easyfun.healthmagicbox.pojo.ConstantData;
import com.easyfun.healthmagicbox.util.SharedPreferencesUtil;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class SettingActivity extends BaseActivity{
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		addbackButton(this);
		
		Button settingButton = (Button) findViewById(R.id.page1_setting_but);	
		Button exitButton = (Button) findViewById(R.id.page1_setting_exit_but);
		
		exitButton.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					SharedPreferences userinfo = SettingActivity.this.getSharedPreferences("UserInfo", MODE_PRIVATE);
		        	
		        	Editor editor = userinfo.edit();

		        	SharedPreferencesUtil spUtil = SharedPreferencesUtil.getInstance(SettingActivity.this);

		        	spUtil.setSTRING_SW("");
					editor.putBoolean("remautologin", false);
					editor.commit();
	            	
					final Intent intent = new Intent(SettingActivity.this, LoginActivity.class);	        	
					startActivity(intent);//
					finish();
					
				}
			
			}
		);
		
		settingButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				String page1_login_passwd_edit = ((EditText) findViewById(R.id.page1_setting_password_edit)).getText().toString();
				String page1_login_passwd_edit2 = ((EditText) findViewById(R.id.page1_setting_password_edit2)).getText().toString();
//				
//				if (password1.length()<6)
//				{
//					Toast.makeText(SettingActivity.this, "密码长度不得小于6位", Toast.LENGTH_LONG).show();
//					return;
//				}
//				if (password1.equals(password2))
//				{
//					Toast.makeText(SettingActivity.this, "保存", Toast.LENGTH_LONG).show();
//				}else
//				{
//					Toast.makeText(SettingActivity.this, "两次密码不一样", Toast.LENGTH_LONG).show();
//				}

				if ((page1_login_passwd_edit==null)||(page1_login_passwd_edit.length()==0)||
						(page1_login_passwd_edit2==null)||(page1_login_passwd_edit2.length()==0))
				{
					Toast.makeText(getApplicationContext(),
							"密码不能为空",
							Toast.LENGTH_SHORT).show();
					return;
				}
				if (!(page1_login_passwd_edit.equals(page1_login_passwd_edit2)))
				{
					Toast.makeText(getApplicationContext(),
							"密码不相同",
							Toast.LENGTH_SHORT).show();
					return;
				}
				if (page1_login_passwd_edit.length()<6)
				{
					Toast.makeText(getApplicationContext(),
							"密码至少六位！",
							Toast.LENGTH_SHORT).show();
					return;
				}
				
				
			}
		});
				
		
	}
}
